package com.wyl.mine.unique.assets

import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.tabs.TabLayout
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.libbase.adapter.SimpleTabSelectedListener
import com.wyl.libbase.base.BindingActivity
import com.wyl.libbase.binding.recyclerview.RecyclerViewDivider
import com.wyl.mine.R
import com.wyl.mine.databinding.AssetsActivityBinding
import io.ditclear.bindingadapter.SingleTypeAdapter
import kotlinx.android.synthetic.main.assets_activity.*
import org.koin.android.viewmodel.ext.android.viewModel

class AssetsActivity : BindingActivity<AssetsActivityBinding>() {
    private val viewModel by viewModel<AssetsViewModel>()

    override fun getLayoutId(): Int = R.layout.assets_activity

    override fun loadData() {
        binding.include.refreshLayout.startRefresh()

        tab.addTab(tab.newTab().setText("全部"))
        tab.addTab(tab.newTab().setText("资产分类1"))
        tab.addTab(tab.newTab().setText("资产分类1"))
        tab.addTab(tab.newTab().setText("资产分类1"))
        tab.addTab(tab.newTab().setText("资产分类1"))
        tab.addTab(tab.newTab().setText("资产分类1"))
        tab.addTab(tab.newTab().setText("资产分类1"))
        tab.addTab(tab.newTab().setText("资产分类1"))
    }

    override fun initView() {
        binding.vm = viewModel

        titleBar.setListener { _, action, _ ->
            when (action) {
                CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                else -> {
                }
            }
        }

        tab.addOnTabSelectedListener(object : SimpleTabSelectedListener() {
            override fun onTabSelected(tab: TabLayout.Tab) {
//                startRefresh(tab.text.toString())
            }
        })

        binding.include.recyclerView.apply {
            layoutManager = LinearLayoutManager(context)
            adapter = mAdapter
            addItemDecoration(RecyclerViewDivider(context, RecyclerViewDivider.VERTICAL))
        }
    }

    private val mAdapter by lazy {
        SingleTypeAdapter(this, R.layout.assets_item, viewModel.dataSource)
            .apply {
                //                itemPresenter = o
//                itemDecorator = object : ItemDecorator {
//                    override fun decorator(
//                        holder: BindingViewHolder<ViewDataBinding>,
//                        position: Int,
//                        viewType: Int
//                    ) {
//                        val itemBinding = holder.binding as AssetsItemBinding
//                        itemBinding.textView5.text = "textView5"
//                    }
//
//                }
            }
    }
}
